﻿using Microsoft.Practices.Unity;
using Sasa.QualityTools.CodeAnalysis.Core.VisualStudio;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Commands.Behaviors.CodeAnalysis.Inspection
{
    public class CreateSolutionInspectorBehavior : CreateCodeInspectorBehaviorBase
    {
        public CreateSolutionInspectorBehavior(IUnityContainer container)
            : base(container)
        {
        }


        public override void Behave(CodeAnalysisCommandExecutionContext context)
        {
            var ide = Container.Resolve<IIde>();
            var solution = ide.Solution;

            if (solution.HasFxCopProjectFile)
            {
                context.Progress.CodeAnalyzers.Add(BuildupCodeAnalysis(solution));
            }
            else
            {
                foreach (var project in solution.GetBuildTargetProjects(true))
                {
                    context.Progress.CodeAnalyzers.Add(BuildupCodeAnalysis(project));
                }
            }
        }
    }
}
